using Microsoft.EntityFrameworkCore;
using MyApp.WebApi.Entity;

namespace MyApp.WebApi.Data
{
    public class Shopping : DbContext
    {
        // 因为我们使用AddDbContext到容器，所以此处必须得有带参数的构造函数（而且必须传递DbContextOptions类型的参数，同时父类也得调用这个参数）
        public Shopping(DbContextOptions options) :
            base(options)
        {
        }

        public DbSet<Users> Users { get; set; }

        public DbSet<UsersGoods> UsersGoods { get; set; }

        public DbSet<UsersInfos> UsersInfos { get; set; }

        public DbSet<UsersOrders> UsersOrders { get; set; }

        public DbSet<Attributes> Attributes { get; set; }

        public DbSet<AttributeValues> AttributeValues { get; set; }

        public DbSet<Catagorys> Catagorys { get; set; }

        public DbSet<Comments> Comments { get; set; }

        public DbSet<CommentTypes> CommentTypes { get; set; }

        public DbSet<Goods> Goods { get; set; }

        public DbSet<GoodsCatagorys> GoodsCatagorys { get; set; }

        public DbSet<GoodsPhotos> GoodsPhotos { get; set; }

        public DbSet<GoodsSpecs> GoodsSpecs { get; set; }
        public DbSet<GoodsAttributes> GoodsAttributes { get; set; }

        // public DbSet<InTurns> InTurns { get; set; }
        public DbSet<InTurns> InTurns { get; set; }

        public DbSet<Orders> Orders { get; set; }

        public DbSet<OrdersSpecs> OrdersSpecs { get; set; }

        public DbSet<PayWays> PayWays { get; set; }

        public DbSet<Photos> Photos { get; set; }

        public DbSet<ShoppingMalls> ShoppingMalls { get; set; }

        public DbSet<Shoppings> Shoppings { get; set; }

        public DbSet<Types> Types { get; set; }

        public DbSet<AuditInfo> AuditInfo { get; set; }

        // protected override void OnConfiguring(
        //     DbContextOptionsBuilder options
        // ) =>
        //     options
        //         .UseSqlServer(@"server=.;database=Shopping;uid=sa;pwd=123456;");
        protected override void OnConfiguring(DbContextOptionsBuilder options)
     => options.UseNpgsql(@"User ID=postgres;Password=123456;Host=47.112.229.147;Port=5432;Database=EShoppingDatabase");

        protected override void OnModelCreating(ModelBuilder model)
        {

            model
                .Entity<GoodsAttributes>()
                .HasData(new GoodsAttributes
                {
                    Id = 1,
                    GoodsId = 1,
                    AttributesId = 1,
                    AttributeValuesId = 1
                }, new GoodsAttributes
                {
                    Id = 2,
                    GoodsId = 1,
                    AttributesId = 1,
                    AttributeValuesId = 2
                }, new GoodsAttributes
                {
                    Id = 3,
                    GoodsId = 1,
                    AttributesId = 2,
                    AttributeValuesId = 3
                }, new GoodsAttributes
                {
                    Id = 4,
                    GoodsId = 1,
                    AttributesId = 2,
                    AttributeValuesId = 4
                }, new GoodsAttributes
                {
                    Id = 5,
                    GoodsId = 1,
                    AttributesId = 2,
                    AttributeValuesId = 5
                }, new GoodsAttributes
                {
                    Id = 6,
                    GoodsId = 2,
                    AttributesId = 1,
                    AttributeValuesId = 1
                }, new GoodsAttributes
                {
                    Id = 7,
                    GoodsId = 2,
                    AttributesId = 1,
                    AttributeValuesId = 2
                }, new GoodsAttributes
                {
                    Id = 8,
                    GoodsId = 2,
                    AttributesId = 2,
                    AttributeValuesId = 3
                }, new GoodsAttributes
                {
                    Id = 9,
                    GoodsId = 2,
                    AttributesId = 2,
                    AttributeValuesId = 4
                }, new GoodsAttributes
                {
                    Id = 10,
                    GoodsId = 2,
                    AttributesId = 2,
                    AttributeValuesId = 5
                }

                );
            model
                  .Entity<Shoppings>()
                  .HasData(new Shoppings
                  {
                      Id = 1,
                      Number = 0,
                      Price = 0,
                      Sum = 0
                  },

              new Shoppings
              {
                  Id = 2,
                  Number = 0,
                  Price = 0,
                  Sum = 0
              });

            model
                .Entity<Users>()
                .HasData(new Users
                {
                    Id = 1,
                    ShoppingsId = 1,
                    Username = "admin",
                    Password = "123",
                    IsManagement = true
                }, new Users
                {
                    Id = 2,
                    ShoppingsId = 2,
                    Username = "mochengi",
                    Password = "123",

                }
                );
            model
                .Entity<Attributes>()
                .HasData(new Attributes { Id = 1, AttributeName = "颜色" },
                new Attributes { Id = 2, AttributeName = "尺寸" });
            model
                .Entity<AttributeValues>()
                .HasData(new AttributeValues { Id = 1, Values = "蓝色" },
                new AttributeValues { Id = 2, Values = "粉色" },
                new AttributeValues { Id = 3, Values = "S" },
                new AttributeValues { Id = 4, Values = "M" },
                new AttributeValues { Id = 5, Values = "L" });
            model
                .Entity<Catagorys>()
                .HasData(new Catagorys
                {
                    Id = 1,
                    ParentId = 0,
                    CatagoryName = "手机",
                    Order = "一级"
                },
                new Catagorys
                {
                    Id = 2,
                    ParentId = 1,
                    CatagoryName = "苹果手机",
                    Order = "二级"
                });
            model
                .Entity<Comments>()
                .HasData(new Comments
                {
                    Id = 1,
                    Comment = "客服服务态度真诚 好评",
                    CommentScore = 100
                },
                new Comments
                {
                    Id = 2,
                    Comment = "手机用起来像素很高 真的好用 爱心爱心",
                    CommentScore = 100
                });
            model
                .Entity<Types>()
                .HasData(new Types { Id = 1, CommentType = "好评" },
                new Types { Id = 2, CommentType = "差评" });
            model
                .Entity<Goods>()
                .HasData(new Goods
                {
                    Id = 1,
                    GoodsName =
                        "正品水滴穿孔P50全网通5G智能手机512GB游戏学生价安卓适用华为线",
                    Description = "高清128G",
                    GoodsCode = 0000012,
                    CurrentPrices = 288.00,
                    Prices = 488.00,
                    Number = 1000
                },
                new Goods
                {
                    Id = 2,
                    GoodsName =
                        "正品水滴穿孔P50全网通5G智能手机512GB游戏学生价安卓适用华为线",
                    Description = "高清128G",
                    GoodsCode = 2313,
                    CurrentPrices = 288.21,
                    Prices = 488.321,
                    Number = 321
                });

            // model
            //   .Entity<InTurns>()
            //   .HasData(new InTurns
            //   {
            //       Id = 1,
            //       InTurn = "https://gtms02.alicdn.com/tps/i2/TB10vPXKpXXXXacXXXXvKyzTVXX-520-280.jpg"
            //   }, new InTurns
            //   {
            //       Id = 2,
            //       InTurn = "https://gtms01.alicdn.com/tps/i1/TB1r4h8JXXXXXXoXXXXvKyzTVXX-520-280.jpg",
            //   }
            //   );
            model
                .Entity<Orders>()
                .HasData(new Orders
                {
                    Id = 1,
                    OrderCode = 0000123,
                    Price = 488.00,
                    TotalMoney = 488.00,
                    Number = 1
                }
                // ,
                // new Orders
                // {
                //     Id = 2,
                //     OrderCode = 133,
                //     Price = 10000.00,
                //     TotalMoney = 10000.00,
                //     Number = 1
                // }
                );
            model
                .Entity<PayWays>()
                .HasData(new PayWays { Id = 1, Ways = "支付宝" },
                new PayWays { Id = 2, Ways = "微信" });
            model
                .Entity<Photos>()
                .HasData(new Photos
                {
                    Id = 1,
                    Picture =
                        "https://gd3.alicdn.com/imgextra/i3/3248078737/O1CN01upM2QW2EPb7f6QL4v_!!3248078737.jpg"
                },
                new Photos
                {
                    Id = 2,
                    Picture =
                        "https://gd1.alicdn.com/imgextra/i1/3248078737/O1CN01CwcifG2EPb7avgdN7_!!3248078737.jpg"
                },
                new Photos
                {
                    Id = 3,
                    Picture =
                        "https://gd3.alicdn.com/imgextra/i3/3248078737/O1CN01uS23E52EPb7cxnmTJ_!!3248078737.jpg"
                });
            model
                .Entity<ShoppingMalls>()
                .HasData(new ShoppingMalls
                {
                    Id = 1,
                    MallName = "就爱淘宝",
                    Logo = "http://localhost:8080/img/logo.f3a91fbc.jpg",
                    ICP = "浙公网安备111000000809010号",
                    Public = "浙ICP备11400800号"
                });
            model
                .Entity<InTurns>()
                .HasData(new InTurns
                {
                    Id = 1,
                    GoodsId = 1,
                    InTurnPictures = "https://gd3.alicdn.com/imgextra/i3/3248078737/O1CN01upM2QW2EPb7f6QL4v_!!3248078737.jpg"
                }, new InTurns
                {
                    Id = 2,
                    GoodsId = 1,
                    InTurnPictures = "https://gd3.alicdn.com/imgextra/i3/3248078737/O1CN01upM2QW2EPb7f6QL4v_!!3248078737.jpg"
                }, new InTurns
                {
                    Id = 3,
                    GoodsId = 2,
                    InTurnPictures = "https://img12.360buyimg.com/n1/s450x450_jfs/t1/190129/33/18394/128789/6119d50cE358c2d65/fd1862a5acfdcc9d.jpg"
                }
                );

            model
                .Entity<UsersInfos>()
                .HasData(new UsersInfos
                {
                    Id = 1,
                    UsersId = 2,
                    Recieve = "超群",
                    TelePhone = 13870613279,
                    Address = "江西省南昌市进贤县204号"
                });
            model
                .Entity<CommentTypes>()
                .HasData(new CommentTypes
                {
                    Id = 1,
                    CommentsId = 1,
                    TypesId = 1
                }, new CommentTypes
                {
                    Id = 2,
                    CommentsId = 2,
                    TypesId = 1
                }
                );
            model
                .Entity<GoodsCatagorys>()
                .HasData(new GoodsCatagorys
                {
                    Id = 1,
                    GoodsId = 1,
                    CatagorysId = 1
                },
                new GoodsCatagorys { Id = 2, GoodsId = 2, CatagorysId = 2 });
            model
                .Entity<GoodsPhotos>()
                .HasData(new GoodsPhotos { Id = 1, GoodsId = 1, PhotosId = 1 },
                new GoodsPhotos { Id = 2, GoodsId = 1, PhotosId = 2 },
                new GoodsPhotos { Id = 3, GoodsId = 2, PhotosId = 3 });

            model
                .Entity<GoodsSpecs>()
                .HasData(new GoodsSpecs
                {
                    Id = 1,
                    AttributesId = 1,
                    AttributeValuesId = 1

                    // Specs="{颜色:蓝色,尺码:X码}"
                },
                new GoodsSpecs
                {
                    Id = 2,
                    AttributesId = 2,
                    AttributeValuesId = 5

                    // Specs="{颜色:蓝色,尺码:X码}"
                });
            model
                .Entity<OrdersSpecs>()
                .HasData(new OrdersSpecs
                {
                    Id = 1,
                    OrdersId = 1,
                    GoodsId = 1,
                    GoodsSpecsId = 1
                },
                new OrdersSpecs
                {
                    Id = 2,
                    OrdersId = 1,
                    GoodsId = 1,
                    GoodsSpecsId = 2
                },
                new OrdersSpecs
                {
                    Id = 3,
                    OrdersId = 1,
                    GoodsId = 2,
                    GoodsSpecsId = 1
                },
                new OrdersSpecs
                {
                    Id = 4,
                    OrdersId = 1,
                    GoodsId = 2,
                    GoodsSpecsId = 2
                });
            model
                .Entity<UsersGoods>()
                .HasData(new UsersGoods
                {
                    Id = 1,
                    GoodsId = 1,
                    UsersId = 2,
                    CommentsId = 1
                },
                new UsersGoods
                {
                    Id = 2,
                    GoodsId = 2,
                    UsersId = 2,
                    CommentsId = 2
                });
            model
                .Entity<UsersOrders>()
                .HasData(new UsersOrders
                {
                    Id = 1,
                    UsersId = 2,
                    OrdersId = 1,
                    PayWaysId = 1
                });
        }
    }
}
